package com.shwread.android.ui.dialog;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

import com.ciko.code.bean.UserBean;
import com.shwread.android.qysw.activity.MainActivity;
import com.shwread.android.ui.page.NewEnterprisePage;
import com.shwread.http.ActionHelp;
import com.shwread.http.TrainActionHelp;

import logic.constants.Const;
import logic.dao.UserDao;


public class NetworkDialog
        extends
        CommonDialog
{
	
	private Activity activity;
	
	public NetworkDialog(Context context) {
		super(context);
		
		activity = (Activity) context;
		tvOk.setText("设置网络");
		tvText.setText("网络未连接，请检查网络设置");
		((Button) vCancel).setText("离线看书");
	}
	
	@Override
	protected void clickOk(View v) {
		super.clickOk(v);
		startWirelessSettingsActivity(activity);
		
		//		activity.finish();
	}
	
	@Override
	protected void clickCancel(View v) {
		UserBean bean = UserDao.getInstance(activity).getLastLoginUser();
		Const.phone_number = bean.getAccount();
		Const.login_key = bean.getKey();
		ActionHelp.setLoginKey(bean.getKey());
		ActionHelp.setAccount(bean.getAccount());
		TrainActionHelp.setLoginKey(bean.getKey());
		TrainActionHelp.setAccount(bean.getAccount());
		NewEnterprisePage.netAvilible = false;
		Intent intent = new Intent(activity, MainActivity.class);
		intent.setAction(MainActivity.TO_BOOKSHELF_ACTION);
		activity.startActivity(intent);
		activity.finish();
		super.clickCancel(v);
		//activity.finish();
	}
	
	public static void startWirelessSettingsActivity(Activity context) {
		try
		{
			Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
			intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
			context.startActivity(intent);
		}
		catch (ActivityNotFoundException e)
		{
			
		}
	}
}
